package com.prpat;


public class Server implements Runnable
{
	@Override
	public void run()
	{
		while(!Thread.interrupted())
		{
			while(!StateTrans.isCurrRangesEmpty())
			{
				synchronized (this) 
				{
					if(!ServerWait.get())
					{
						try 
						{
							//TODO set the waiting time
							wait(10000);
						} 
						catch (Exception e) {}
					}
					ServerWait.set(true);
				}
				Message temp = StateTrans.deqRng();
				if(temp != null){
					PendingContainer.insert(temp);
					Sender.sendMessage(temp);
				}
				else
					continue;
			}//Thread was interrupted
			StateTrans.sealHash("","Uncracked", "");
			try {
				throw new InterruptedException();
			} catch (InterruptedException e) {
				System.err.println("Server InterruptedException");
				// TODO server was stopped
			}
			System.err.println("Server outa loop");
		}
	}

}
